package com.example.readinternalfile;

import java.io.FileInputStream;
import java.io.InputStream;

import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
	public static final String FILE_NAME="danhsachlop.txt";
	private TextView tvContentFile;
	private TextView tvContentRaww;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvContentFile=(TextView)findViewById(R.id.tvContent);
        tvContentRaww=(TextView)findViewById(R.id.tvContentRaw);
        //cac buoc xu li doc file
        try{
        	//buoc 1 mo 1 file
        	FileInputStream fis = openFileInput(FILE_NAME);
        	//buoc 2 thuc hien xu li doc
        	byte[] reader = new byte[fis.available()];
        	if(fis.read(reader) !=-1){
        		String myData = new String(reader);
        		tvContentFile.setText(myData);
        		
        	}
        }
        catch (Exception e) {
			// TODO: handle exception
		}
        
        //doc file trong thu muc raw
        try{
        	//buoc 1 mo 1 file
        	Resources resource = getResources();
        	InputStream input = resource.openRawResource(R.raw.danhsachlop);
        	
        	//buoc 2 thuc hien xu li doc
        	byte[] reader = new byte[input.available()];
        	if(input.read(reader) !=-1){
        		String myData = new String(reader);
        		tvContentRaww.setText(myData);
        		
        	}
        }
        catch (Exception e) {
			// TODO: handle exception
		}
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
